import * as types from "./constant";
/**
 * 全局布局状态相关
 */
export default {
    state: {
        //来源路由名称
        fromName: '',
        //来源路由名称
        toName: '',
        // 路由title
        title: '',
        // 动画效果
        direction: 'forward',
        // 全局loading
        loading: false,
        // 定位loading
        locationLoading: false,
    },
    actions: {
        fromName({ commit }, name) {
            commit(types.APP_FROMNAME, name)
        },
        toName({ commit }, name) {
            commit(types.APP_TONAME, name)
        },
        title({ commit }, title) {
            commit(types.APP_TITLE, title)
        },
        direction({ commit }, direction) {
            commit(types.APP_DIRECTION, direction)
        },
        loading({ commit }, loading = true) {
            commit(types.APP_LOADING, loading)
        },
        locationing({ commit }, loading = true) {
            commit(types.APP_LOCATION_LOADING, loading)
        },
    },
    mutations: {
        [types.APP_FROMNAME](state, payload) {
            state.fromName = payload
        },
        [types.APP_TONAME](state, payload) {
            state.toName = payload
        },
        [types.APP_TITLE](state, payload) {
            document.title = payload
            state.title = payload
        },
        [types.APP_DIRECTION](state, payload) {
            state.direction = payload
        },
        [types.APP_LOADING](state, payload) {
            state.loading = payload
        },
        [types.APP_LOCATION_LOADING](state, payload) {
            state.locationLoading = payload
        },
    },
    getters: {
        fromName(state) {
            return state.fromName
        },
        toName(state) {
            return state.toName
        },
        loading(state) {
            return state.loading
        },
        locationLoading(state) {
            return state.locationLoading
        },
        direction(state) {
            return state.direction
        },
    }
}